<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../js/tools/jquery-1.4.2.min.js"></script>

<style>
table{table-layout:fixed;font-size:12px;}
  tr{background-color:#F1F6F6;}
  td{border:1px solid #D9D9D9;color:black;padding:2px;}
</style>
<script type="text/javascript">
    var isSuccessEmail=false;
 function checkUserEmail()
 {
    var email=$.trim($("#email").val());
     var str = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
     $("#errorInfor").remove();      
     
    if(email=="")
    {
      alert("Email 不能为空！");
      isSuccessEmail=false;
    }else if(!str.test(email))
    {
      alert("Email 格式不对！");
      isSuccessEmail=false;
    }else
    {
       
	    $.getJSON("../../groupbyajax/user!checkUserEmail.action",{email:email},function(data){
            var div='';
            if(!data.success)
            {
               isSuccessEmail=true;
               $("#errorInfor").remove();
               div="<span id='errorInfor' ><font color='blue'>Email 可以使用！</font></span>";
            }else
            {
				$("#errorInfor").remove();
               isSuccessEmail=false;
               div="<span id='errorInfor' ><font color='red'>Email 已经存在，请用其它的！</font></span>";
            }
            $("#email").after(div); 
            
	    });
    }
    return false;
 }
 
     function modifyEmail()
     {
	 	checkUserEmail();
		if(!isSuccessEmail)
		{
			return false;
		}
        var password='<s:property value="#session.user.password"/>';
		if(password!=$("#password").val())
		{
			alert("你输入的登录密码错误");
			return false;
		}
		var email=$("#email").val();
		$.getJSON("../../groupbyajax/user!modifyEmail.action",{email:email},function(data){
			if(data.success)
			{
				alert("修改成功!");
			}
		});
     }
</script>
</head>
<body>
 
 <table  style="width:80%;" align="center">
 <tr><td width="200">你现在使用的邮箱地址：</td><td><input type="text" id="oldemail" readonly=true value="<s:property value="#session.user.email"/>"/></td></tr>
 <tr>
    <td >你的密码:</td>
    <td>
       <input type="text" id="password"/>
    </td>
</tr>
<tr>
    <td >你想设置的新登录邮箱:</td>
    <td>
       <input type="text" id="email" onblur="checkUserEmail()"/>
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
       <input type="button" value="保存" onclick="modifyEmail()">
    </td>
</tr>
</table>

</body>
</html>